package ksv.cron.v1.impl;

import api.common.http.Http;
import ksv.cron.CronContext;
import ksv.cron.CronCst;
import ksv.cron.CronModel;
import ksv.cron.bean.SysCron;
import ksv.cron.v1.CronCallback;
import okhttp3.OkHttpClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @创建人 wsdc
 * @时间 2021/2/1
 * @描述 使用okhttp来回调
 */
public class OkHttpCronCallback implements CronCallback {

    @Override
    public Mono<CronModel.R> execute(CronContext context) {
        return Mono.just(new CronModel.R());
    }

    @Override
    public CronModel.R execute0(CronContext context) {
        SysCron sysCron = context.getICron().sysCron();
        String callbackUrl = sysCron.getCallbackUrl();
        Map<String, Object> bodyMap = sysCron.getParamMap();
        return Http.postJson(callbackUrl, bodyMap, CronModel.R.class);
    }

    @Override
    public String type() {
        return CronCst.CallWay.HTTP;
    }


}
